<?php
	include_once 'header.php';
	//Array ( [gid] => Array ( [0] => 2 [1] => 4 ) [gnum] => Array ( [0] => 3 [1] => 13 ) )
	//print_r($_POST);
	//echo 'select a.gid,a.num carnum,a.newprice,b.gname,b.gphoto,b.zkprice,b.num from (select gid,num,newprice,newdate from kp_carlist where uid=? and gid in('.implode(',', $_POST['gid']).') order by newdate desc) a left join kp_goods b on a.gid = b.gid';
	
	if(isset($_POST['gid']) && !empty($_POST['gid'])){
		$stmt = $pdo->prepare('select a.gid,a.num carnum,a.newprice,b.gname,b.gphoto,b.zkprice,b.num from (select gid,num,newprice,newdate from kp_carlist where uid=? and gid in('.implode(',', $_POST['gid']).') order by newdate desc) a left join kp_goods b on a.gid = b.gid');
		$stmt->execute(array($uid));
		$goodArr = $stmt->fetchAll(PDO::FETCH_ASSOC);
		//print_r($goodArr);
	}else{
		//echo '<script type="text/javascript">location.href = \'carlist.php\';</script>';
	}
	
	//查询出地址
	$stmtU = $pdo->prepare('select * from kp_usr_address where uid = ?');
	$stmtU -> execute(array($uid));
	$arrU = $stmtU->fetchAll(PDO::FETCH_ASSOC);
	 

	

?>
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<script src="js/jquery-3.1.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/getorder.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="css/getorder.css"/>
		<title>结算页</title>
	</head>
	<body>
		<!--<form action="" method="post">-->
			
			
		
		<div id="getorder">
			<div class="goods">
				<div class="title">
					<h2>您的位置: 订单结算</h2>
				</div>
				<!--订单商品详情-->
				<ul class="goodtitle">
					<li class="c0">编号</li>
					<li class="c1">名称</li>
					<li class="c2">单价</li>
					<li class="c3">数量</li>
					<li class="c4">小计</li>
				</ul>
				<?php 
					$sum = 0.0;
					foreach($goodArr as $good){
				?>
				<ul class="good" id="<?php echo 'g_'.$good['gid']; ?>">
					<li class="c0"><?php echo $good['gid']; ?></li>
					<li class="c1"><?php echo $good['gname']; ?></li>
					<li class="c2"><?php echo $good['zkprice']; ?></li>
					<li class="c3"><?php echo $good['carnum']; ?></li>
					<li class="c4"><?php echo number_format(($good['zkprice']* $good['carnum']),2,'.','') ?></li>
				</ul>
				<?php 
					$sum += ($good['zkprice']* $good['carnum']);
					} 
				?>
				<!--订单商品详情-->
				<ul class="goodtitle">
					<li class="c0">汇总:</li>
					<li class="c1">&nbsp;</li>
					<li class="c2">&nbsp;</li>
					<li class="c3">&nbsp;</li>
					<li class="c4"><?php echo number_format($sum,2,'.','') ?></li>
				</ul>	

			</div>
			<!--管理收货地址-->
			<hr />
			<br />收货信息选择:<br />
			<?php 
				foreach($arrU as $u){
			?>
			<ul id="" class="address">
				<li><input type="radio" <?php if($u['isdefault'] == 1) echo 'checked="checked"'; ?> name="address" value="<?php echo $u['id'] ?>" /></li>
				<li><?php echo $u['address']; ?></li>
				<li><?php echo $u['uname']; ?></li>
				<li><?php echo $u['tel']; ?></li>
			</ul>
			<?php } ?>
			<!--支付方式:余额-->
			<hr />
			<br />支付方式选择:<br />
			<ul id="pays">
				<li><input type="radio" checked="checked" name="payfs" value="1" />余额支付</li>
			</ul>
			<div id="gopay">
				<input type="button" name="submit" id="submit" value="提交订单" onclick="submitpay(<?php echo "'".implode(',', $_POST['gid'])."'"; ?>)" />
			</div>
		</div>
		<!--</form>-->
	</body>
</html>

